﻿using LightOMator.Helper;
using GalaSoft.MvvmLight;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LightOMator.ViewModel
{
    public class BusyViewModel : ViewModelBase, IBusyViewModel
    {
        private bool _isBusy;
        public bool IsBusy
        {
            get { return _isBusy; }
            set
            {
                if (value != _isBusy)
                {
                    _isBusy = value;
                    RaisePropertyChanged();
                }
            }
        }

        private int _busyCounter;

        public void IncreaseBusyCounter()
        {
            lock (this)
            {
                _busyCounter++;
                IsBusy = true;
            }
        }

        public void DecreaseBusyCounter()
        {
            lock (this)
            {
                int counter = _busyCounter - 1;
                if (counter < 0)
                {
                    counter = 0;
                }
                _busyCounter = counter;
                if (counter == 0)
                {
                    IsBusy = false;
                }
            }
        }


        public string Localize(string resourceName, params object[] parameters)
        {
            return GlobalizationHelper.Localize(resourceName, parameters);
        }

        public virtual void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
        }
    }
}
